def run_algorithmPastFiveNetDay(outlets, user, green, power, utility)
	   data = []
	   preference = user.last.consumption_preference
	   util_cntrl_lvl = user.last.utility_control_lvl
	   or_lvl = utility.override_lvl
	   
	   checked =[]
	   checked = PowerLog.find(:all, :order => "id desc", :limit => 5)
	   sum = 0
	   for checked.each do |check|
	   		sum = sum + check.power_consumption
	   	end
	   	avg = sum/5
		avg_percent = green / avg
		
		
		
	   for outlet in outlets
	   	 if outlet.user_override == true and (outlet.or_time + (30)) < (Time.now - (5*60*60))
	   	 	outlet.user_override = false
	   	 	o = OutletStatus.find(outlet.id)
	   	 	outlet.or_time = Time.now
			o.update_attribute(:user_override, 0)
		 end
	   	 if outlet.user_override == false
			 if outlet.priority >= util_cntrl_lvl and or_lvl <= outlet.priority
				preference = 7
			 else
				preference = user.last.consumption_preference
			 end
			case preference
			when preference = 1
			 if outlet.priority != 1 and outlet.status == true
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 0)
			 elsif outlet.priority == 1 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			 end
			when preference = 2
			  if avg_percent >= 0.8 and outlet.priority < 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent >= 1 and outlet.priority == 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent < 0.8 and outlet.priority == 2 and outlet.status == true
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 0)
			  elsif avg_percent < 1 and outlet.priority == 3 and outlet.status == true
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 0)
			  end
			when preference = 3
			  if avg_percent >= 0.4 and outlet.priority < 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent >= 0.6 and outlet.priority == 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent < 0.4 and outlet.priority > 1 and outlet.status == true
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 0)
			  end
			when preference = 4
			  if avg_percent >= 0.1 and outlet.priority < 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent >= 0.3 and outlet.priority == 3 and outlet.status == false
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 1)
			  elsif avg_percent < 0.1 and outlet.priority > 1 and outlet.status == true
				data << outlet.outlet_id
				o = OutletStatus.find(outlet.id)
				o.update_attribute(:status, 0)
			  end
			when preference = 5
				if outlet.status == false
				  data << outlet.outlet_id
				  o = OutletStatus.find(outlet.id)
				  o.update_attribute(:status, 1)
				end
			when preference = 6
				if outlet.priority < 3 and outlet.status == false
				  data << outlet.outlet_id
				  o = OutletStatus.find(outlet.id)
				  o.update_attribute(:status, 1)
				elsif outlet.priority == 3 and outlet.status == true
				  data << outlet.outlet_id
				  o = OutletStatus.find(outlet.id)
				  o.update_attribute(:status, 0)
				end
			when preference = 7
				if outlet.status == true
				  data << outlet.outlet_id
				  o = OutletStatus.find(outlet.id)
				  o.update_attribute(:status, 0)
				end
			end
		 end
	   end
	    return data
	end
